package band.wukong.practice.java.core.topic.concurrency.thread.scheduling;

import java.io.IOException;

/**
 * 使用join()方法，等待其他线程运行结束
 *
 * @author wukong(wukonggg@139.com)
 */
public class JoinSample implements Runnable {

    public void run() {
        for (int a = 0; a < 100; a++) {
            System.out.println(Thread.currentThread().getName() + ":" + a + "  ");
        }
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        Thread t = new Thread(new JoinSample());
        t.setName("m1");
        t.start();
        System.out.println("main: join t");
        t.join();  //主线程等待m1运行结束
        System.out.println("main: end");
    }
}
